/*
 * @Author: Leng
 * @Date: 2021-02-02 16:08:44
 * @Description: 加载时执行函数
 * @FilePath: \vue-leng\src\config\execut.js
 */

const execut = {}

execut.install = () => {
    // 解决ios因软键盘弹出导致元素偏移的问题
    const isIphone = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
    let keybordShow = false
    document.body.addEventListener('focusin', (e) => {
        keybordShow = true
        setTimeout(function () {
            fixLayout(e)
        }, 500)
    })
    document.body.addEventListener('focusout', () => {
        keybordShow = false
        setTimeout(function () {
            fixLayout()
        }, 100)
    })

    function fixLayout(e) {
        if (isIphone) {
            if (!keybordShow) {
                window.scroll(document.body.scrollHeight, 0)
                // document.body.scrollTop = document.body.scrollHeight
                // document.body.scrollTop = 0;
            }
        } else {
            if (e && e.target.nodeName == 'INPUT') {
                keybordShow && e.target.scrollIntoView(false)
            }
        }
    }

    // 初始化加载iconfont
    $tool.loadIconfont()
}

export default execut